import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import WindiCSS from 'vite-plugin-windicss'
import path from 'path'
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
export default defineConfig({
    resolve: {
        alias: {
            "~": path.resolve(__dirname, "src"),
        }
    },
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
        '/ws':{
          target: 'http://localhost:8080',
            ws:true, // 启用 WebSocket 代理
            changeOrigin: true,
        }
    },
  },
    plugins: [vue(), WindiCSS()],
    optimizeDeps: {
        esbuildOptions: {
            define: {
                global: 'globalThis', // 将 global 替换为 globalThis
            },
            plugins: [
                NodeGlobalsPolyfillPlugin({
                    buffer: true,
                }),
            ],
        },
    },
})
